home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16270 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: newsfeed.gsfc.nasa.gov!usenet
  2. From: tycho <vonrosen@nssdca.gsfc.nasa.gov>
  3. Newsgroups: comp.lang.c++
  4. Subject: sprintf() in C++
  5. Date: 9 Apr 1996 22:13:24 GMT
  6. Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA
  7. Message-ID: <4kene4$nkb@post.gsfc.nasa.gov>
  8. NNTP-Posting-Host: tycho.gsfc.nasa.gov
  9.  
  10. I could use some help with regard to sprintf() in C++.  It seems that 
  11. cout and cin were invented to avoid printf() and scanf() because the
  12. latter have variable argument lists and hence can't be checked against
  13. function prototypes.  But is there any corresponding C++ approach to
  14. sprintf() and sscanf()?  When I look at various string class functions
  15. I don't see what to use instead of sprintf() and sscanf().  But when I
  16. look at my C code, I'm using sprintf() and sscanf() all the time.  It
  17. seems very clumsy to cast a string object to a character array, use
  18. sprintf() to write to it and then convert the result back to a string 
  19. object.  And, of course, using sprintf() means that the compiler can't 
  20. check against a prototype.  So what am I missing?  I have examined a
  21. number of standard texts and they don't seem to ever go into this when
  22. talking about strings.  K&R discuss sprintf() and sscanf() under the
  23. heading of "In-memory Format Conversion", but these functions do much
  24. more than that.
  25.  
  26. As a newcomer to C++ I will appreciate any assistance you can give.
  27.  
  28. Thanks,
  29.  
  30. Tycho von Rosenvinge
  31.  
  32.